﻿namespace wToggl
{
    using Windows.UI.Core;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;

    public sealed partial class LoginDialog
    {
        private bool isApiToken;

        public LoginDialog(bool isApiToken = false)
        {
            this.InitializeComponent();
            this.isApiToken = isApiToken;

            if (!isApiToken)
            {
                return;
            }

            this.EmailBox.Visibility = Visibility.Collapsed;
            this.PasswordBox.Header = "Toggl API token";
        }

        public string Email
        {
            get
            {
                return this.EmailBox.Text;
            }
        }

        public string Password
        {
            get
            {
                return this.PasswordBox.Password;
            }
        }

        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            
        }

        private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {

        }

        private void LoginDialog_OnLoaded(object sender, RoutedEventArgs e)
        {
            if (this.isApiToken)
            {
                this.Dispatcher.RunAsync(
                    CoreDispatcherPriority.High,
                    () =>
                        {
                            this.PasswordBox.Focus(FocusState.Keyboard);
                        });
            }
            else
            {
                this.Dispatcher.RunAsync(
                    CoreDispatcherPriority.High,
                    () =>
                        {
                            this.EmailBox.Focus(FocusState.Keyboard);
                        });
            }
        }
    }
}
